|
|
|
|
|
|
|
Figure 13.23
Perspective projection of a cube containing
the center of projection. |
|
|
|
|
|
|
|
|
One easy way to prevent all these odd effects is to check whether either of a line segment's endpoints lies beside or behind the center of projection. If so, clip that segment out of the picture and do not draw it. |
|
|
|
|
|
|
|
|
The ideal time to decide whether a point is behind the center of projection is after translating and rotating the center of projection into the Z axis but before performing the perspective transformation. At that point, you can check to see if the Z coordinate of the point is smaller than the Z coordinate of the center of projection. If so, the point lies in front of the center of projection, so you can draw it. |
|
|
|
|
|
|
|
|
Unfortunately, when you apply a perspective transformation to a point, you destroy the point's Z coordinate information. That means you can no longer compare the points' Z coordinates to see if they lie behind the center of projection. However, if you modify the perspective transformation matrix and the way transformations are applied to points, you can preserve the Z coordinate information. |
|
|
|
|
|
|
|
|
First, change the perspective transformation matrix so that the Z coordinate is not lost. |
|
|
|
|
|
|
|
|
Now when you multiply a point [x, y, z, 1] with this new matrix you get: |
|
|
|
|
|